<script>
export default {
    data() {
        return {  
            layerClass:"modal fade",
            active:"coupons open",
            copuon_middle:[{
			"code": "",
			"over": "",
			"off": ""
            }],
            isNewCustomer:false,
            canGetCoupon:false,
            rawBody:"",
            text_old_new:"You Have Got the Coupons!",
            loading:false
        }
    },
    
    created: function () {
        this.loadData();
    },
    methods: {
     async loadData(){
            Ios.getIsIOS();
            let Data = await Ios.getAllUserInfo();
            sessionStorage.setItem('raw-body', Data);
            this.rawBody = Data;
            // console.log(Data);
            this.loading = true;
            $ajax.get('https://app-v1.soufeel.com/market/coupon').then((result) => {       
                this.loading = false;       
                //this.list = result
                this.isNewCustomer = result.response.isNewCustomer;
                this.canGetCoupon = result.response.canGetCoupon;
                this.copuon_middle= result.response.coupons;
                if(this.isNewCustomer && this.canGetCoupon){
                    this.active = "coupons";
                }
                
                if(!this.isNewCustomer){
                    this.active = "coupons open";
                    this.text_old_new = "For New Customers Registered From June 18th, 2018."
                }
            }).catch((error) => {
                 this.loading = false;
                console.log(error);
            });
        },
        getCoupons(){

            if(!this.canGetCoupon || !this.isNewCustomer){
                return false;
            }
            this.loading = true;
            $ajax.post('https://app-v1.soufeel.com/market/coupon/receive').then((result) => {               
                //this.list = result
                this.loading = false;  
                if(result.response.header.rspCode == 0){
                    //alert coupon layer
                    this.layerClass = "modal fade open"
                    this.active = "coupons open";
                    this.canGetCoupon  = false;
                }else{
                    //alert message
                    Message.error(result.response.header.rspdesc);
                }
            }).catch((error) => {
                console.log(error);
            });
            
        },
        modalRemoveClass() {
            this.layerClass = "modal fade";        
        },
        jumpToMe(){
            Ios.callNewWebView({title:"Me",url:"myclient://Me"});
        }
        
    }
}
</script>
